﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BO;

namespace ProjectQuaDep
{
    public partial class DetailNews : System.Web.UI.Page
    {
        private int ZoneID = 0;
        protected string urlFB = "";
        protected string urlZone = "";
        protected string titleZone = "";
        protected string title = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            int NewsID = lib.NewsID;
            if (NewsID > 0)
            {
                DataTable dt = BO.News.NewsBO.GetDetailNewsBO(NewsID.ToString());
                if (dt.Rows.Count > 0)
                {
                    string newsID = dt.Rows[0][Const.tbNews.id].ToString();
                     title = ltTitle.Text = Utils.EnCodeString(dt.Rows[0][Const.tbNews.Title].ToString());
                    string href = BO.ReWriteUrl.BuildLink.BuildLinkNews(newsID);
                    string avatar = dt.Rows[0][Const.tbNews.Avatar].ToString();
                    string sapo = ltSapo.Text = dt.Rows[0][Const.tbNews.Sapo].ToString();
                    string sTime =
                        ltTime.Text =
                        "Ngày viết: " +
                        DateTime.Parse(dt.Rows[0][Const.tbNews.DistributionDate].ToString()).ToString("dd/MM/yyyy");
                    string longContent = ltcontent.Text = dt.Rows[0][Const.tbNews.longContent].ToString();
                    ZoneID = int.Parse(dt.Rows[0][Const.tbNews.ZoneIdOther].ToString().TrimEnd(','));
                    //title zone
                    urlZone = BO.ReWriteUrl.BuildLink.BuildLinkZoneNews(ZoneID.ToString());
                    DataTable dtZone = BO.News.ZoneBO.GetDetailZoneBO(ZoneID.ToString());
                    if (dtZone != null && dtZone.Rows.Count > 0)
                    {
                        DataRow dr = dtZone.Rows[0];
                        titleZone = dr[BO.Const.tbZoneNews.url].ToString();
                    }
                    //
                    urlFB = Const.sHttpDomain + href;
                    //set meta
                    Page.Title = title;
                    string hDesc = sapo;
                    string hKey = title;
                    BAL.Utils.AddMeta(this.Page, BAL.Const.MetaAttributes.Description.Id,
                                      BAL.Const.MetaAttributes.Description.Name, hDesc);
                    BAL.Utils.AddMeta(this.Page, BAL.Const.MetaAttributes.Keywords.Id,
                                      BAL.Const.MetaAttributes.Keywords.Name, hKey);
                    BAL.Utils.AddMeta(this.Page, BAL.Const.MetaAttributes.NewKeywords.Id,
                                      BAL.Const.MetaAttributes.NewKeywords.Name, hKey);
                }
            }
        }
    }
}